import numpy as np
import matplotlib.pyplot as plt

# 定义特征列和聚类中心值
# features = ['基本认识', '主观意愿', '作用意义', '传播推广']
features = ['', '', '', '']
cluster_centers = [
    [7, 5, 9, 6],
    [5, 1, 2, 3],
    [8, 9, 9, 9],
    [5, 6, 2, 6]
]
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams.update({'font.size': 16})  # 设置全局字体大小为16
# 设置雷达图参数
labels = np.array(features)
num_vars = 4
# 绘制每个聚类中心的雷达图
for i, center in enumerate(cluster_centers):
    fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))

    angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist()
    stats = np.concatenate((center, [center[0]]))
    angles += angles[:1]

    ax.fill(angles, stats, color='skyblue', alpha=0.4)
    ax.plot(angles, stats, color='blue', linewidth=3, linestyle='solid')
    ax.set_yticklabels([])

    # 设置刻度
    tick_values = np.linspace(0, 2*np.pi, len(labels), endpoint=False)
    ax.set_xticks(tick_values)
    ax.set_xticklabels(labels)

    # 添加数据标签
    for angle, stat in zip(angles, stats):
        ax.text(angle, stat + 0.5, str(stat), ha='center', va='center', fontsize=20,
                bbox=dict(facecolor='yellow', edgecolor='blue'))

    # 添加雷达图内部的数值范围
    ax.set_ylim(0, 10)

    # 添加雷达图内部的刻度线
    for angle in angles:
        ax.plot([angle, angle], [0, 10], color='black', alpha=0.3)  # 添加竖直方向的刻度线
    plt.title('{}类'.format(['B', 'D', 'A', 'C'][i]), color='red')

plt.show()
